import asyncio
import websockets

ws = "ws://192.168.66.10:8080/ws/nodes/9FF97291/json"
ws = "ws://192.168.66.10:8080/ws/uplink/90607A45"

async def listen_to_server():
    async with websockets.connect(ws) as websocket:
        print('成功连接到服务器')

        while True:
            message = await websocket.recv()
            print('接收到服务器消息:', message)
            
            await websocket.send('{"data": "313131313131", "port": 12}')


async def send_to_server():
    async with websockets.connect(ws) as websocket:
        print('成功连接到服务器')

        # 发送消息到服务器
        message = input('请输入要发送的消息:')
        await websocket.send(message)
        print('已发送消息到服务器')

# 创建事件循环，并运行两个协程
loop = asyncio.get_event_loop()
tasks = asyncio.gather(listen_to_server())
loop.run_until_complete(tasks)